# 树的结点值(好题)
# 2025/5/16
import sys

sys.setrecursionlimit(5000)


def tree_node_values_dfs(n, arr):
    # 构建树结构
    tree = [[] for _ in range(n + 1)]  # tree中的第i个数组表示节点i的子节点
    tree[0].append(1)
    for idx, r in enumerate(arr):
        tree[r].append(idx + 2)

    res = [(0, 0)] * (n + 1)

    def dfs(curr):
        if curr % 2 == 1:
            odd, even = 1, 0
        else:
            odd, even = 0, 1

        for son in tree[curr]:
            s_odd, s_even = dfs(son)
            odd += s_odd
            even += s_even
        res[curr] = (odd, even)
        return odd, even

    dfs(1)
    for i in range(1, n + 1):
        print(res[i][(i + 1) % 2])


def tree_node_values_stack(n, arr):
    # 构建树结构
    tree = [[] for _ in range(n + 1)]  # tree中的第i个数组表示节点i的子节点
    tree[0].append(1)
    for idx, r in enumerate(arr):
        tree[r].append(idx + 2)

    # 重点在于每个节点需要访问两次
    res = [(0, 0)] * (n + 1)
    stack = [(1, False)]  # (当前节点, 是否已经遍历)
    while stack:
        curr, visited = stack.pop()
        if not visited:  # 第一次访问, 初始化奇偶计数
            if curr % 2 == 1:
                res[curr] = (1, 0)
            else:
                res[curr] = (0, 1)
            stack.append((curr, True))
            for son in reversed(tree[curr]):
                stack.append((son, False))
        else:  # 第二次访问, 累加奇偶值
            for son in tree[curr]:
                res[curr] = (res[curr][0] + res[son][0], res[curr][1] + res[son][1])

    for i in range(1, n + 1):
        print(res[i][(i + 1) % 2])


if __name__ == '__main__':
    n = int(input())
    tree_arr = []
    for i in range(n - 1):
        tree_arr.append(int(input()))
    tree_node_values_dfs(n, tree_arr)  # dfs会造成递归溢出
    tree_node_values_stack(n, tree_arr)
